<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" type="text/css" href="/dcms/Public/common.css" />
	<script type="text/javascript" src="/dcms/Public/Admin/resources/scripts/jquery-1.7.2.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/dcms/Public/Boot/bootstrap.min.css" />
	<script type="text/javascript" src="/dcms/Public/Boot/bootstrap.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/dcms/Public/Button/css/font-awesome.min.css" />
</head>
<body>
	<div>
		<p>
 		 <button type="button" class="btn btn-primary ">模型列表</button>
 		 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">添加模型</button>
 		 <button type="button" id="element" onclick="cache(this)" class="btn btn-info">更新缓存</button>
 		 <span class="Upcache"  style="width:80px;height:20px;display: inline-block; color:blue; display: none;">缓存成功</span>
		</p>
	</div>
	<!-- 模型缓存 -->
	<script type="text/javascript">
	function cache(obj){
		$.get("<?php echo U('updateCache');?>",function(data){
			if(data==1){
				$(".Upcache").fadeIn('2000').fadeOut('1000');
			}else{
				$(".Upcache").html("缓存失败");
				$(".Upcache").fadeIn('1000').fadeOut('1000');
			}
		})
	}
	</script>

	<div class="table-responsive">
  		<table class="table table-striped">
    		<tr>
				<td class="w100">mid</td>
				<td>模型名称</td>
				<td>表名</td>
				<td class="w200">操作</td>
			</tr>
			<?php if(is_array($data)): $i = 0; $__LIST__ = $data;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$d): $mod = ($i % 2 );++$i;?><tr>
				<td class="w100"><?php echo ($d["mid"]); ?></td>
				<td><?php echo ($d["m_name"]); ?></td>
				<td><?php echo ($d["m_table_name"]); ?></td>
				<td class="w300">
					<a href="<?php echo U('Filed/index',array('mid'=>$d['mid']));?>" class="btn btn-default icon-cog">字段管理</a>
					<a href="javascript:;"  attr="<?php echo ($d["mid"]); ?>" onclick="return edit(this)" class="btn btn-default  icon-edit" data-toggle="modal" data-target="#edit">修改</a>
					<a href="javascript:;" tname="<?php echo ($d["m_table_name"]); ?>" attr="<?php echo ($d["mid"]); ?>" onclick="return del(this)" class="btn btn-default  icon-cut">删除</a>
				</td>
			</tr><?php endforeach; endif; else: echo "" ;endif; ?>
  		</table>
	</div>

<!-- 删除 -->
<script type="text/javascript">
	function del(obj){
		if(confirm('确认要删除吗？')){
			var mid = $(obj).attr('attr');
			var tname=$(obj).attr('tname');
			$.post("<?php echo U('del');?>",{mid:mid,m_table_name:tname},function(data){
				if(data==1){
					$(obj).parent('td').parent('tr').remove();
				}
			})
		}
		return false;
	}
</script>
<!-- 添加模型弹窗 -->
<form action="<?php echo U('Model/add');?>"  method="post">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">添加模型</h4>
      		</div>
     		 <div class="modal-body">
     		 	
       			 <table class="table">
       			 	<tr class="warning">
       			 		<td>模型名型：</td>
       			 		<td>
       			 			<input type="text" name="m_name" class="form-control" placeholder="输入模型名称">
       			 		</td>
       			 	</tr>
					<tr class="success">
						<td>表名：</td>
						<td>
							<input type="text" name="m_table_name" class="form-control" placeholder="表名">
						</td>
					</tr>
					
       			 </table>

     		 </div>
      		<div class="modal-footer">
        <button type="submit" class="btn btn-primary">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</form>

<!-- 编辑模型弹窗 -->
<script type="text/javascript">
	function edit(obj){
		var mid=$(obj).attr('attr');
		var xiu=null;
		var shuju=<?php echo ($shuju); ?>;
		$.each(shuju,function(k,v){
			if(k==mid){
				xiu=v;
			}
		});	
		$('#edit .m_name').val(xiu.m_name);
		$('#edit .mid').val(xiu.mid);
		$('#edit .m_table_name').val(xiu.m_table_name);
	}
</script>


<form action="<?php echo U('Model/edit');?>" method="post">
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">修改模型</h4>
      		</div>
     		 <div class="modal-body">
     		 	<input class="mid" type="hidden" name='mid' value="">
       			 <table class="table">
       			 	<tr class="warning">
       			 		<td>模型名型：</td>
       			 		<td>
       			 			<input  type="text" name="m_name" class="form-control m_name" value="">
       			 		</td>
       			 	</tr>
					<tr class="success">
						<td>表名：</td>
						<td>
							<input type="text" name="m_table_name" class="form-control m_table_name" value="">
						</td>
					</tr>
					
       			 </table>

     		 </div>
      		<div class="modal-footer">
        <button type="submit" class="btn btn-primary">提交</button>
       	 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</form>

</body>
</html>